package com.phantasy.loaders
{
	import com.phantasy.loaders.gameLoader.ResourceItem;
	
	import flash.display.Loader;
	
	public class Decoder extends Loader
	{
		public var decodelist:Array;
		public var isDecoding:Boolean;
		public var info:ResourceItem;
		
		public function Decoder()
		{
			this.decodelist = [];
			super();
		}
		
		public function add(item:ResourceItem):void
		{
			this.decodelist.push(item);
			this.start();
		}
		
		private function start():void
		{
			if ((this.isDecoding == true)|| (this.decodelist.length == 0))
			{
				return
			}
			try
			{
				this.info = this.decodelist.shift();
				loadBytes(this.info.content);
				this.isDecoding = true;
			}
			catch(e:Error)
			{
				isDecoding = false;
			}
		}
		
		public function dispose():void
		{
			this.isDecoding = false;
			this.unload();
			this.start();
		}
	}
}